package com.itheima.accountingdb.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.accountingdb.pojo.Transaction;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @author panweiwei
 */
@Mapper
public interface TransactionMapper extends BaseMapper<Transaction> {
    /**
     * 分页查询交易记录
     * @param page
     * @param size
     * @param startDate
     * @param endDate
     * @param type
     * @param categoryId
     * @return
     */
    List<Transaction> list(Integer page, Integer size, String startDate, String endDate, String type, String categoryId,Long isDeleted);


    /**
     * 添加交易记录
     * @param transaction
     */
    @Insert("insert into transaction(user_id,category_id,amount,type,transaction_date,remark) values(#{userId},#{categoryId},#{amount},#{type},#{transactionDate},#{remark})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int add(Transaction transaction);

    /**
     * 更新交易记录
     * @param transaction
     */
    int update(Transaction transaction);

    /**
     * 删除交易记录
     * @param id
     */
    @Update("update transaction set is_deleted = 1 where id = #{id}")
    void delete(Long id);

    /**
     * 获取交易记录汇总报表
     * @param userId
     * @param startDate
     * @param endDate
     * @param categoryId
     * @return
     */
    Map<String, Object> getSummaryReport(Long userId, String startDate, String endDate, Integer categoryId);


    /**
     * 获取图表数据
     * @param startDate
     * @param endDate
     * @param type
     * @return
     */
    List<Map<String, Object>> getChartData(String startDate, String endDate, String type);
}
